import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';
import 'package:yqys_target/utils/yq_colors.dart';
import 'package:yqys_target/widgets/form_list_item.dart';
import 'package:yqys_target/pages/organization/controllers/organization_auth_controller.dart';
import 'package:yqys_target/widgets/xh_auto_height_text_field.dart';
import 'package:yqys_target/widgets/yq_date_picker.dart';
import 'package:yqys_target/widgets/adress_picker/address_picker.dart';

class BusinessInfoPage extends StatelessWidget {
  const BusinessInfoPage({super.key});

  @override
  Widget build(BuildContext context) {
    final controller = Get.find<OrganizationAuthController>();
    
    return SingleChildScrollView(
      padding: const EdgeInsets.all(16),
      child: DefaultTextStyle(
        style: TextStyle(fontSize: 15, color: YQColors.primary),
        child: Column(
          children: [
            // 第一组
            ClipRRect(
              borderRadius: BorderRadius.circular(10),
              child: Container(
                color: Colors.white,
                child: Column(
                  children: [
                    FormListItem(
                      title: "统一码",
                      trailing: SizedBox(
                        width: 200,
                        child: XHAutoHeightTextField(
                          maxLength: 30,
                          width: 200,
                          placeholder: "请输入统一码",
                        ),
                      ),
                    ),
                    FormListItem(
                      title: "注册资金",
                      trailing: SizedBox(
                        width: 200,
                        child: XHAutoHeightTextField(
                          maxLength: 30,
                          width: 200,
                          placeholder: "请输入注册资金",
                        ),
                      ),
                    ),
                    FormListItem(
                      title: "成立登记日期",
                      trailing: SizedBox(
                        width: 200,
                        child: YQDatePicker(
                          placeholder: "请选择成立登记日期",
                        ),
                      ),
                    ),
                    FormListItem(
                      title: "登记管理机关",
                      trailing: SizedBox(
                        width: 200,
                        child: XHAutoHeightTextField(
                          maxLength: 30,
                          width: 200,
                          placeholder: "请输入登记管理机关",
                        ),
                      ),
                    ),
                    FormListItem(
                      title: "业务主管单位",
                      trailing: SizedBox(
                        width: 200,
                        child: XHAutoHeightTextField(
                          maxLength: 30,
                          width: 200,
                          placeholder: "请输入业务主管单位",
                        ),
                      ),
                    ),
                    FormListItem(
                      title: "机构类型",
                      trailing: SizedBox(
                        width: 200,
                        child: XHAutoHeightTextField(
                          maxLength: 30,
                          width: 200,
                          placeholder: "请输入机构类型",
                        ),
                      ),
                    ),
                    FormListItem(
                      hideDivider: true,
                      title: "证书有效期",
                      trailing: SizedBox(
                        width: 200,
                        child: YQDatePicker(
                          placeholder: "请选择证书有效期",
                        ),
                      ),
                    ),
                  ],
                ),
              ),
            ),
            const SizedBox(height: 16),
            // 第二组
            ClipRRect(
              borderRadius: BorderRadius.circular(10),
              child: Container(
                color: Colors.white,
                child: Column(
                  children: [
                    FormListItem(
                      title: "选择地区",
                      trailing: SizedBox(
                        width: 200,
                        child: GestureDetector(
                          onTap: () {
                            showModalBottomSheet(
                              backgroundColor: Colors.white,
                              context: context,
                              builder: (context) => Container(
                                height: 250.0,
                                child: Column(
                                  children: [
                                    Expanded(
                                      child: AddressPicker(
                                        mode: AddressPickerMode.provinceAndCity,
                                        isShowTopHeader: false,
                                        bgColor: Colors.white,
                                        style: const TextStyle(fontSize: 16, color: Colors.black),
                                        firstFlexColor: Colors.white,
                                        secondFlexColor: Colors.white,
                                        onSelectedAddressChanged: (address) {
                                          if (address.currentProvince != null && address.currentCity != null) {
                                            controller.updateSelectedAddress('${address.currentProvince!.province} ${address.currentCity!.city}');
                                          }
                                        },
                                        // onTapEnter: () {
                                        //   controller.updateSelectedAddress('${address.currentProvince!.province} ${address.currentCity!.city}');
                                        // },
                                      ),
                                    ),
                                  ],
                                ),
                              ),
                            );
                          },
                          child: GetBuilder<OrganizationAuthController>(
                            builder: (controller) => Container(
                              height: 36,
                              padding: const EdgeInsets.symmetric(horizontal: 12),
                              decoration: BoxDecoration(
                                color: Colors.white,
                                borderRadius: BorderRadius.circular(8),
                              ),
                              child: Row(
                                mainAxisAlignment: MainAxisAlignment.end,
                                children: [
                                  Text(
                                    controller.selectedAddress ?? "请选择地区",
                                    style: TextStyle(
                                      fontSize: 16,
                                      color: controller.selectedAddress != null ? Colors.black : Colors.grey,
                                    ),
                                  ),
                                ],
                              ),
                            ),
                          ),
                        ),
                      ),
                    ),
                    FormListItem(
                      title: "地址",
                      trailing: SizedBox(
                        width: 200,
                        child: XHAutoHeightTextField(
                          maxLength: 30,
                          width: 200,
                          placeholder: "请输入地址",
                        ),
                      ),
                    ),
                    FormListItem(
                      title: "邮箱",
                      trailing: SizedBox(
                        width: 200,
                        child: XHAutoHeightTextField(
                          maxLength: 30,
                          width: 200,
                          placeholder: "请输入邮箱",
                        ),
                      ),
                    ),
                    FormListItem(
                      title: "电话",
                      trailing: SizedBox(
                        width: 200,
                        child: XHAutoHeightTextField(
                          maxLength: 30,
                          width: 200,
                          placeholder: "请输入电话",
                        ),
                      ),
                    ),
                    FormListItem(
                      hideDivider: true,
                      title: "机构官网",
                      trailing: SizedBox(
                        width: 200,
                        child: XHAutoHeightTextField(
                          maxLength: 30,
                          width: 200,
                          placeholder: "请输入机构官网",
                          placeholderStyle: const TextStyle(color: Colors.grey),
                          textStyle: const TextStyle(color: Colors.black),
                        ),
                      ),
                    ),
                  ],
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
} 